using System.Collections.Generic;
using Map;
using MoonFramework.Template;
using Sirenix.OdinInspector;
using UnityEngine;

namespace Config
{
    /// <summary>
    /// 掉落物配置
    /// </summary>
    [CreateAssetMenu(fileName = "掉落配置", menuName = "Config/掉落配置")]
    public class LootConfig : BaseConfig
    {
        [LabelText("掉落配置列表")] public List<LootConfigModel> ConfigModels;

        public void GetMapObject(BaseMapBlock mapBlock, Vector3 position)
        {
            foreach (var loot in ConfigModels)
            {
                //根据概率决定是否实例化
                int randValue = Random.Range(1, 101);
                if (randValue > loot.Probability) continue;
                //生成掉落物体
                Vector3 pos = position + Vector3.up;
                MapManager.Instance.CreateMapObject(mapBlock, loot.LootObjectID, pos);
            }            
        }
    }

    public struct LootConfigModel
    {
        [LabelText("掉落物ID")] public int LootObjectID;
        [LabelText("掉落概率")] public int Probability;
    }
}